<template>
	<view class="">
		<view class="">
			专题页内容
			<view class="">2023光能杯报名开始</view>
		</view>
		<view class="fixed-bottom">
			<button class="bg_main text-white font" @click="apply">{{ gnbInfo.type == 2 ? '开始投票' : '马上参加' }}</button>
		</view>
		<u-modal :show="modelShow" title="通知" @confirm="modelShow = false">
			<view class="slot-content text-center">
				<view class="font-md">贵企业已提交报名，请勿重复报名</view>
				<view class="c_6 font_24 mt-2">如有问题请拨打客服电话：188232329807</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
import { voteParticipate } from '@/api/my/gnb_apply.js';
import { getUserInfo } from '@/api/my/userinfo.js';
export default {
	data() {
		return {
			gnbInfo: {},
			modelShow: false,
			audit: '',
			grade: null
		};
	},
	onLoad(option) {
		this.grade = option.grade; //账号类型
		this.info();
	},
	methods: {
		info() {
			// 获取光能杯参评投票信息
			return new Promise((resolve, reject) => {
				voteParticipate({ uid: uni.getStorageSync('userInfo').userId }).then(res => {
					if (res.code == 0) {
						this.gnbInfo = res.data;
						resolve();
					} else {
						uni.$u.toast(res.msg);
						reject();
					}
				});
			});
		},
		apply() {
			if (!uni.getStorageSync('userInfo').hasLogin) {
				this.toLogin();
				return;
			}
			this.auth().then(res => {
				if (this.audit != 1) {
					// 未认证企业
					uni.showModal({
						title: '通知',
						content: '您当前未完成企业认证，请完成认证后报名参与',
						confirmColor: '#E30012',
						confirmText: '前往认证',
						success: res => {
							if (res.confirm) {
								this.toAuth(this.audit);
							} else {
								return;
							}
						}
					});
				} else {
					// 已认证企业
					this.info().then(res => {
						if (this.gnbInfo.type == 1) {
							// 申请参评
							if (this.grade == 2 || this.grade == 4) {
								if (this.gnbInfo.is_participate == 1) {
									// 已申请参加
									this.modelShow = true;
								} else {
									// 未申请参加，跳转报名页面
									uni.navigateTo({
										url: '/subPages/my/gnb_vote/apply_from?activeId=' + this.gnbInfo.activity_id
									});
								}
							} else {
								uni.$u.toast('抱歉，您暂无权限参加评选~');
							}
						} else {
							// 开始投票
							uni.navigateTo({
								url: '/subPages/my/gnb_vote/vote?activityId=' + this.gnbInfo.activity_id
							});
						}
					});
				}
			});
		},
		auth() {
			/* 获取用户是否认证 */
			return new Promise((resolve, reject) => {
				getUserInfo({
					token: uni.getStorageSync('userInfo').token
				}).then(res => {
					console.log('用户数据', res);
					if (res.code == 0) {
						this.audit = res.data.member.audit;
						resolve();
					} else {
						uni.$u.toast(res.msg);
						reject();
					}
				});
			});
		}
	}
};
</script>

<style></style>
